

/* This optional program produces a standardized set of 
race categories using a modified version of code available 
through IPUMS website (based on a program for IPUMS-USA by 
Liebler and Halpern-Manners). It produces a set of 
probabilities that a given respondent is each race which are used to identify
a single race for each respondent with a consistent method across years.

It also produes dummy variables for racial groups. 

These variables facilitate linking between 2002 and 2003, race categories were updated
to allow multiple responses. Checks in 03_linking.do must remove references to ONERACE
and race dummies (WHiTE, BLACK, AMIND, API, and RACOTHER) if this program is not run.)


	Original author: Sheela Kennedy (last update June 8, 2020)
	
	Created by SK    : June 08, 2020 
	Last updated	 : Jan 12, 2024
	
*/

clear
set more off

* User must fill in the paths and file names for the following local macros *
local indir "../replication-package"
local setup "data/setup/01_setup.dta"
local racebridge "data/setup/02_racebridge.dta"

capture cd "`indir'"
use "`setup'", clear

/*generating dummy vars for each race; if specified race
is listed as one of respondent's races, they are coded a 2
for that dummy. People who list multiple races will be coded
a 2 for multiple dummies.*/
gen white=1
replace white=2 if race==100|race==801|race==802|race==803|race==804|race==810|race==811|race==812|race==813|race==814|race==816|race==817|race==819
tab white

gen black=1
replace black=2 if race==200|race==801|race==805|race==806|race==807|race==810|race==811|race==814|race==816|race==818
tab black

gen amind=1
replace amind=2 if race==300|race==802|race==805|race==808|race==810|race==812|race==814|race==815|race==817|race==818|race==819
tab amind

gen api=1
replace api=2 if race==650|race==651|race==652|race==803|race==804|race==806|race==807|race==808|race==809|race==811|race==812|race==813|race==814|race==815|race==816|race==817|race==818|race==819
tab api

gen racother=1
replace racother=2 if race==700|race==820|race==830
tab racother

/*note: this deviates slightly from source code in that 
the response "four or five races, unspecified" is coded
as belonging to the "other race" category. In IPUMS-USA,
four or five races is not an option. It is an option in CPS,
though it accounts for only 0.01% of respondents.*/

label variable white "Race: white"
label variable black "Race: Black"
label variable amind "Race: American Indian/Alaskan Native"
label variable api "Race: Asian Pacific Islander"
label variable racother "Race: some other race"

label define raceyn 1 "No" 2 "Yes (alone or in combo)", replace

foreach v of varlist white black amind api racother {
	label value `v' raceyn
	}


/*Generating MRMRACE categories*/
gen mrmrace=.
replace mrmrace=1 if amind==2 & api==2 & black==1 & white==1
replace mrmrace=2 if amind==2 & api==1 & black==2 & white==1
replace mrmrace=3 if amind==2 & api==1 & black==1 & white==2
replace mrmrace=4 if amind==1 & api==2 & black==2 & white==1
replace mrmrace=5 if amind==1 & api==2 & black==1 & white==2
replace mrmrace=6 if amind==1 & api==1 & black==2 & white==2
replace mrmrace=7 if amind==2 & api==2 & black==2 & white==1
replace mrmrace=8 if amind==2 & api==2 & black==1 & white==2
replace mrmrace=9 if amind==2 & api==1 & black==2 & white==2
replace mrmrace=10 if amind==1 & api==2 & black==2 & white==2
replace mrmrace=11 if amind==2 & api==2 & black==2 & white==2
replace mrmrace=20 if amind==2 & api==1 & black==1 & white==1
replace mrmrace=30 if amind==1 & api==2 & black==1 & white==1
replace mrmrace=40 if amind==1 & api==1 & black==2 & white==1
replace mrmrace=50 if amind==1 & api==1 & black==1 & white==2
replace mrmrace=60 if racother==2

gen age10=age/10

gen hispanic=1
replace hispanic=0 if hispan==0|hispan==901|hispan==902
/*note: this deviates slightly from source code so that respondents who said
they do not know or did not respond to question about hispanic origin are coded
as non-hispanic.*/

gen male=0 if sex==2
replace male=1 if sex==1

/*Generating modified regression method bridging variables. Basically 
unmodified from Liebler & Halpern-Manners. Note that this uses their sources
on the racial composition of states as of April 1, 2000.*/
gen lnpctAI=0	
 label variable lnpctAI "natural log of %AI in state"
replace lnpctAI=	-0.693147181	if statefip==	1	
replace lnpctAI=	2.753660712	if statefip==	2	
replace lnpctAI=	1.648658626	if statefip==	4	
replace lnpctAI=	-0.356674944	if statefip==	5	
replace lnpctAI=	0.182321557	if statefip==	6	
replace lnpctAI=	0.182321557	if statefip==	8	
replace lnpctAI=	-1.203972804	if statefip==	9	
replace lnpctAI=	-0.916290732	if statefip==	10	
replace lnpctAI=	-1.203972804	if statefip==	11	
replace lnpctAI=	-0.916290732	if statefip==	12	
replace lnpctAI=	-1.203972804	if statefip==	13	
replace lnpctAI=	-1.203972804	if statefip==	15	
replace lnpctAI=	0.336472237	if statefip==	16	
replace lnpctAI=	-1.203972804	if statefip==	17	
replace lnpctAI=	-1.203972804	if statefip==	18	
replace lnpctAI=	-1.203972804	if statefip==	19	
replace lnpctAI=	0		if statefip==	20	
replace lnpctAI=	-1.609437912	if statefip==	21	
replace lnpctAI=	-0.510825624	if statefip==	22	
replace lnpctAI=	-0.510825624	if statefip==	23	
replace lnpctAI=	-1.203972804	if statefip==	24	
replace lnpctAI=	-1.203972804	if statefip==	25	
replace lnpctAI=	-0.510825624	if statefip==	26	
replace lnpctAI=	0.09531018	if statefip==	27	
replace lnpctAI=	-0.916290732	if statefip==	28	
replace lnpctAI=	-0.693147181	if statefip==	29	
replace lnpctAI=	1.824549292	if statefip==	30	
replace lnpctAI=	-0.105360516	if statefip==	31	
replace lnpctAI=	0.336472237	if statefip==	32	
replace lnpctAI=	-1.609437912	if statefip==	33	
replace lnpctAI=	-1.203972804	if statefip==	34	
replace lnpctAI=	2.282382386	if statefip==	35	
replace lnpctAI=	-0.693147181	if statefip==	36	
replace lnpctAI=	0.262364264	if statefip==	37	
replace lnpctAI=	1.589235205	if statefip==	38	
replace lnpctAI=	-1.609437912	if statefip==	39	
replace lnpctAI=	2.079441542	if statefip==	40	
replace lnpctAI=	0.336472237	if statefip==	41	
replace lnpctAI=	-1.609437912	if statefip==	42	
replace lnpctAI=	-0.510825624	if statefip==	44	
replace lnpctAI=	-0.916290732	if statefip==	45	
replace lnpctAI=	2.116255515	if statefip==	46	
replace lnpctAI=	-1.203972804	if statefip==	47	
replace lnpctAI=	-0.356674944	if statefip==	48	
replace lnpctAI=	0.336472237	if statefip==	49	
replace lnpctAI=	-0.916290732	if statefip==	50	
replace lnpctAI=	-1.203972804	if statefip==	51	
replace lnpctAI=	0.470003629	if statefip==	53	
replace lnpctAI=	-1.609437912	if statefip==	54	
replace lnpctAI=	-0.105360516	if statefip==	55	
replace lnpctAI=	0.832909123	if statefip==	56	
				
gen pctAI=0	
 label variable pctAI "% Am.Ind. in state"			
replace pctAI=	0.5	if statefip==	1	
replace pctAI=	15.7	if statefip==	2	
replace pctAI=	5.2	if statefip==	4	
replace pctAI=	0.7	if statefip==	5	
replace pctAI=	1.2	if statefip==	6	
replace pctAI=	1.2	if statefip==	8	
replace pctAI=	0.3	if statefip==	9	
replace pctAI=	0.4	if statefip==	10	
replace pctAI=	0.3	if statefip==	11	
replace pctAI=	0.4	if statefip==	12	
replace pctAI=	0.3	if statefip==	13	
replace pctAI=	0.3	if statefip==	15	
replace pctAI=	1.4	if statefip==	16	
replace pctAI=	0.3	if statefip==	17	
replace pctAI=	0.3	if statefip==	18	
replace pctAI=	0.3	if statefip==	19	
replace pctAI=	1	if statefip==	20	
replace pctAI=	0.2	if statefip==	21	
replace pctAI=	0.6	if statefip==	22	
replace pctAI=	0.6	if statefip==	23	
replace pctAI=	0.3	if statefip==	24	
replace pctAI=	0.3	if statefip==	25	
replace pctAI=	0.6	if statefip==	26	
replace pctAI=	1.1	if statefip==	27	
replace pctAI=	0.4	if statefip==	28	
replace pctAI=	0.5	if statefip==	29	
replace pctAI=	6.2	if statefip==	30	
replace pctAI=	0.9	if statefip==	31	
replace pctAI=	1.4	if statefip==	32	
replace pctAI=	0.2	if statefip==	33	
replace pctAI=	0.3	if statefip==	34	
replace pctAI=	9.8	if statefip==	35	
replace pctAI=	0.5	if statefip==	36	
replace pctAI=	1.3	if statefip==	37	
replace pctAI=	4.9	if statefip==	38	
replace pctAI=	0.2	if statefip==	39	
replace pctAI=	8	if statefip==	40	
replace pctAI=	1.4	if statefip==	41	
replace pctAI=	0.2	if statefip==	42	
replace pctAI=	0.6	if statefip==	44	
replace pctAI=	0.4	if statefip==	45	
replace pctAI=	8.3	if statefip==	46	
replace pctAI=	0.3	if statefip==	47	
replace pctAI=	0.7	if statefip==	48	
replace pctAI=	1.4	if statefip==	49	
replace pctAI=	0.4	if statefip==	50	
replace pctAI=	0.3	if statefip==	51	
replace pctAI=	1.6	if statefip==	53	
replace pctAI=	0.2	if statefip==	54	
replace pctAI=	0.9	if statefip==	55	
replace pctAI=	2.3	if statefip==	56	


gen pctAPI=0				
 label variable pctAPI "% Asian or PI in state"		
replace pctAPI=	0.8	if statefip==	1	
replace pctAPI=	4.7	if statefip==	2	
replace pctAPI=	2.1	if statefip==	4	
replace pctAPI=	0.9	if statefip==	5	
replace pctAPI=	11.8	if statefip==	6	
replace pctAPI=	2.5	if statefip==	8	
replace pctAPI=	2.6	if statefip==	9	
replace pctAPI=	2.2	if statefip==	10	
replace pctAPI=	2.8	if statefip==	11	
replace pctAPI=	1.8	if statefip==	12	
replace pctAPI=	2.3	if statefip==	13	
replace pctAPI=	56.7	if statefip==	15	
replace pctAPI=	1.1	if statefip==	16	
replace pctAPI=	3.6	if statefip==	17	
replace pctAPI=	1	if statefip==	18	
replace pctAPI=	1.3	if statefip==	19	
replace pctAPI=	1.9	if statefip==	20	
replace pctAPI=	0.8	if statefip==	21	
replace pctAPI=	1.3	if statefip==	22	
replace pctAPI=	0.8	if statefip==	23	
replace pctAPI=	4.1	if statefip==	24	
replace pctAPI=	4	if statefip==	25	
replace pctAPI=	1.9	if statefip==	26	
replace pctAPI=	3	if statefip==	27	
replace pctAPI=	0.7	if statefip==	28	
replace pctAPI=	1.2	if statefip==	29	
replace pctAPI=	0.6	if statefip==	30	
replace pctAPI=	1.4	if statefip==	31	
replace pctAPI=	5.3	if statefip==	32	
replace pctAPI=	1.4	if statefip==	33	
replace pctAPI=	6	if statefip==	34	
replace pctAPI=	1.3	if statefip==	35	
replace pctAPI=	5.9	if statefip==	36	
replace pctAPI=	1.5	if statefip==	37	
replace pctAPI=	0.6	if statefip==	38	
replace pctAPI=	1.2	if statefip==	39	
replace pctAPI=	1.5	if statefip==	40	
replace pctAPI=	3.4	if statefip==	41	
replace pctAPI=	1.9	if statefip==	42	
replace pctAPI=	2.5	if statefip==	44	
replace pctAPI=	1	if statefip==	45	
replace pctAPI=	0.6	if statefip==	46	
replace pctAPI=	1.1	if statefip==	47	
replace pctAPI=	2.9	if statefip==	48	
replace pctAPI=	2.5	if statefip==	49	
replace pctAPI=	0.9	if statefip==	50	
replace pctAPI=	3.9	if statefip==	51	
replace pctAPI=	6.1	if statefip==	53	
replace pctAPI=	0.6	if statefip==	54	
replace pctAPI=	1.8	if statefip==	55	
replace pctAPI=	0.7	if statefip==	56	
				
gen pctB=0						
 label variable pctB "% Black in state"		
replace pctB=	26.1	if statefip==	1	
replace pctB=	3.7	if statefip==	2	
replace pctB=	3.3	if statefip==	4	
replace pctB=	15.7	if statefip==	5	
replace pctB=	7	if statefip==	6	
replace pctB=	4	if statefip==	8	
replace pctB=	9.8	if statefip==	9	
replace pctB=	19.6	if statefip==	10	
replace pctB=	61.1	if statefip==	11	
replace pctB=	15.2	if statefip==	12	
replace pctB=	29	if statefip==	13	
replace pctB=	1.9	if statefip==	15	
replace pctB=	0.5	if statefip==	16	
replace pctB=	15.3	if statefip==	17	
replace pctB=	8.5	if statefip==	18	
replace pctB=	2.2	if statefip==	19	
replace pctB=	5.9	if statefip==	20	
replace pctB=	7.4	if statefip==	21	
replace pctB=	32.6	if statefip==	22	
replace pctB=	0.6	if statefip==	23	
replace pctB=	28.3	if statefip==	24	
replace pctB=	6.4	if statefip==	25	
replace pctB=	14.4	if statefip==	26	
replace pctB=	3.7	if statefip==	27	
replace pctB=	36.4	if statefip==	28	
replace pctB=	11.3	if statefip==	29	
replace pctB=	0.3	if statefip==	30	
replace pctB=	4.1	if statefip==	31	
replace pctB=	7	if statefip==	32	
replace pctB=	0.8	if statefip==	33	
replace pctB=	14.4	if statefip==	34	
replace pctB=	2.1	if statefip==	35	
replace pctB=	17.6	if statefip==	36	
replace pctB=	21.8	if statefip==	37	
replace pctB=	0.6	if statefip==	38	
replace pctB=	11.6	if statefip==	39	
replace pctB=	7.7	if statefip==	40	
replace pctB=	1.7	if statefip==	41	
replace pctB=	10.3	if statefip==	42	
replace pctB=	5.7	if statefip==	44	
replace pctB=	29.7	if statefip==	45	
replace pctB=	0.7	if statefip==	46	
replace pctB=	16.5	if statefip==	47	
replace pctB=	11.8	if statefip==	48	
replace pctB=	0.9	if statefip==	49	
replace pctB=	0.5	if statefip==	50	
replace pctB=	19.9	if statefip==	51	
replace pctB=	3.4	if statefip==	53	
replace pctB=	3.2	if statefip==	54	
replace pctB=	5.8	if statefip==	55	
replace pctB=	0.8	if statefip==	56	
				
gen pctBsq=0				
  label variable pctBsq "% Black in state, squared"
replace pctBsq=	681.21	if statefip==	1	
replace pctBsq=	13.69	if statefip==	2	
replace pctBsq=	10.89	if statefip==	4	
replace pctBsq=	246.49	if statefip==	5	
replace pctBsq=	49	if statefip==	6	
replace pctBsq=	16	if statefip==	8	
replace pctBsq=	96.04	if statefip==	9	
replace pctBsq=	384.16	if statefip==	10	
replace pctBsq=	3733.21	if statefip==	11	
replace pctBsq=	231.04	if statefip==	12	
replace pctBsq=	841	if statefip==	13	
replace pctBsq=	3.61	if statefip==	15	
replace pctBsq=	0.25	if statefip==	16	
replace pctBsq=	234.09	if statefip==	17	
replace pctBsq=	72.25	if statefip==	18	
replace pctBsq=	4.84	if statefip==	19	
replace pctBsq=	34.81	if statefip==	20	
replace pctBsq=	54.76	if statefip==	21	
replace pctBsq=	1062.76	if statefip==	22	
replace pctBsq=	0.36	if statefip==	23	
replace pctBsq=	800.89	if statefip==	24	
replace pctBsq=	40.96	if statefip==	25	
replace pctBsq=	207.36	if statefip==	26	
replace pctBsq=	13.69	if statefip==	27	
replace pctBsq=	1324.96	if statefip==	28	
replace pctBsq=	127.69	if statefip==	29	
replace pctBsq=	0.09	if statefip==	30	
replace pctBsq=	16.81	if statefip==	31	
replace pctBsq=	49	if statefip==	32	
replace pctBsq=	0.64	if statefip==	33	
replace pctBsq=	207.36	if statefip==	34	
replace pctBsq=	4.41	if statefip==	35	
replace pctBsq=	309.76	if statefip==	36	
replace pctBsq=	475.24	if statefip==	37	
replace pctBsq=	0.36	if statefip==	38	
replace pctBsq=	134.56	if statefip==	39	
replace pctBsq=	59.29	if statefip==	40	
replace pctBsq=	2.89	if statefip==	41	
replace pctBsq=	106.09	if statefip==	42	
replace pctBsq=	32.49	if statefip==	44	
replace pctBsq=	882.09	if statefip==	45	
replace pctBsq=	0.49	if statefip==	46	
replace pctBsq=	272.25	if statefip==	47	
replace pctBsq=	139.24	if statefip==	48	
replace pctBsq=	0.81	if statefip==	49	
replace pctBsq=	0.25	if statefip==	50	
replace pctBsq=	396.01	if statefip==	51	
replace pctBsq=	11.56	if statefip==	53	
replace pctBsq=	10.24	if statefip==	54	
replace pctBsq=	33.64	if statefip==	55	
replace pctBsq=	0.64	if statefip==	56	

gen pct2race=0	
 label variable pct2race "% 2+ races or non-hispanic 'other' in state"		
replace pct2race=	0.8	if statefip==	1	
replace pct2race=	4.6	if statefip==	2	
replace pct2race=	1.3	if statefip==	4	
replace pct2race=	1.1	if statefip==	5	
replace pct2race=	2.2	if statefip==	6	
replace pct2race=	1.6	if statefip==	8	
replace pct2race=	1.1	if statefip==	9	
replace pct2race=	1.1	if statefip==	10	
replace pct2race=	1.3	if statefip==	11	
replace pct2race=	1	if statefip==	12	
replace pct2race=	0.9	if statefip==	13	
replace pct2race=	15.2	if statefip==	15	
replace pct2race=	1.3	if statefip==	16	
replace pct2race=	0.9	if statefip==	17	
replace pct2race=	0.9	if statefip==	18	
replace pct2race=	0.8	if statefip==	19	
replace pct2race=	1.5	if statefip==	20	
replace pct2race=	0.8	if statefip==	21	
replace pct2race=	0.7	if statefip==	22	
replace pct2race=	0.8	if statefip==	23	
replace pct2race=	1.3	if statefip==	24	
replace pct2race=	1.1	if statefip==	25	
replace pct2race=	1.3	if statefip==	26	
replace pct2race=	1.2	if statefip==	27	
replace pct2race=	0.6	if statefip==	28	
replace pct2race=	1.1	if statefip==	29	
replace pct2race=	1.5	if statefip==	30	
replace pct2race=	1	if statefip==	31	
replace pct2race=	2.1	if statefip==	32	
replace pct2race=	0.8	if statefip==	33	
replace pct2race=	1.1	if statefip==	34	
replace pct2race=	1.4	if statefip==	35	
replace pct2race=	1.3	if statefip==	36	
replace pct2race=	0.9	if statefip==	37	
replace pct2race=	0.9	if statefip==	38	
replace pct2race=	1.1	if statefip==	39	
replace pct2race=	4	if statefip==	40	
replace pct2race=	2.1	if statefip==	41	
replace pct2race=	0.8	if statefip==	42	
replace pct2race=	1.3	if statefip==	44	
replace pct2race=	0.7	if statefip==	45	
replace pct2race=	1.1	if statefip==	46	
replace pct2race=	0.8	if statefip==	47	
replace pct2race=	0.9	if statefip==	48	
replace pct2race=	1.2	if statefip==	49	
replace pct2race=	1	if statefip==	50	
replace pct2race=	1.3	if statefip==	51	
replace pct2race=	2.6	if statefip==	53	
replace pct2race=	0.8	if statefip==	54	
replace pct2race=	0.9	if statefip==	55	
replace pct2race=	1.2	if statefip==	56	

* 14 states have no cities of more than 1 million population
* source for total state pop & # not metro: Census table GCT-PH1: state

gen medmetro= 0
 label variable medmetro "MSA less than 1 million"
replace medmetro=	0.6991	 if statefip==	1	
replace medmetro=	0.4152	 if statefip==	2	
replace medmetro=	0.8001	 if statefip==	10	
replace medmetro=	0.7232	 if statefip==	15	
replace medmetro=	0.3925	 if statefip==	16	
replace medmetro=	0.4532	 if statefip==	19	
replace medmetro=	0.3660	 if statefip==	23	
replace medmetro=	0.3386	 if statefip==	30	
replace medmetro=	0.5258	 if statefip==	31	
replace medmetro=	0.5690	 if statefip==	35	
replace medmetro=	0.4422	 if statefip==	38	
replace medmetro=	0.3457	 if statefip==	46	
replace medmetro=	0.2782	 if statefip==	50	
replace medmetro=	0.3000	 if statefip==	56	

gen nonmetro= 0
 label variable nonmetro "not in metro area"
replace nonmetro=	0.3009	 if statefip==	1	
replace nonmetro=	0.5848	 if statefip==	2	
replace nonmetro=	0.1999	 if statefip==	10	
replace nonmetro=	0.2768	 if statefip==	15	
replace nonmetro=	0.6075	 if statefip==	16	
replace nonmetro=	0.5468	 if statefip==	19	
replace nonmetro=	0.6340	 if statefip==	23	
replace nonmetro=	0.6614	 if statefip==	30	
replace nonmetro=	0.4742	 if statefip==	31	
replace nonmetro=	0.4310	 if statefip==	35	
replace nonmetro=	0.5578	 if statefip==	38	
replace nonmetro=	0.6543	 if statefip==	46	
replace nonmetro=	0.7218	 if statefip==	50	
replace nonmetro=	0.7000	 if statefip==	56	

/* 11 states and DC have 1+ 'big' city and no big cities cross 
  its state lines
* source for central city population is: Census table GCT-PH1: 
  Population, Housing Units, Area, and Density: 2000 (SF1) 
  US and PR -- Metropolitan Area, in Central City, Not in 
  Central City, County, and (in selected States) County Subdivision*/
  
gen bigurban= 0
 label variable bigurban "in central city, MSA >= 1 million"
replace bigurban=	0.30194982	 if statefip==	6	
replace bigurban=	0.128947302	 if statefip==	8	
replace bigurban=	0.048375233	 if statefip==	9	
replace bigurban=	1		 if statefip==	11	
replace bigurban=	0.146517683	 if statefip==	12	
replace bigurban=	0.050873559	 if statefip==	13	
replace bigurban=	0.114202672	 if statefip==	22	
replace bigurban=	0.142947226	 if statefip==	26	
replace bigurban=	0.454740787	 if statefip==	36	
replace bigurban=	0.182724202	 if statefip==	40	
replace bigurban=	0.300103396	 if statefip==	48	
replace bigurban=	0.127595807	 if statefip==	49	

gen bigsubrb= 0
 label variable bigsubrb "outside central city, MSA >= 1 million"
replace bigsubrb=	0.461780454	 if statefip==	6	
replace bigsubrb=	0.361439587	 if statefip==	8	
replace bigsubrb=	0.299029676	 if statefip==	9	
replace bigsubrb=	0	 	 if statefip==	11	
replace bigsubrb=	0.488469989	 if statefip==	12	
replace bigsubrb=	0.451443867	 if statefip==	13	
replace bigsubrb=	0.185133462	 if statefip==	22	
replace bigsubrb=	0.413484445	 if statefip==	26	
replace bigsubrb=	0.300745866	 if statefip==	36	
replace bigsubrb=	0.131229616	 if statefip==	40	
replace bigsubrb=	0.28697212	 if statefip==	48	
replace bigsubrb=	0.469723071	 if statefip==	49	

replace medmetro=	0.203166702	 if statefip==	6	
replace medmetro=	0.348356912	 if statefip==	8	
replace medmetro=	0.608941541	 if statefip==	9	
replace medmetro=	0	 	 if statefip==	11	
replace medmetro=	0.29337837	 if statefip==	12	
replace medmetro=	0.189882725	 if statefip==	13	
replace medmetro=	0.454798594	 if statefip==	22	
replace medmetro=	0.265574873	 if statefip==	26	
replace medmetro=	0.165288916	 if statefip==	36	
replace medmetro=	0.294151775	 if statefip==	40	
replace medmetro=	0.261381836	 if statefip==	48	
replace medmetro=	0.167735626	 if statefip==	49	

replace nonmetro=	0.033103025	 if statefip==	6	
replace nonmetro=	0.161256199	 if statefip==	8	
replace nonmetro=	0.043653549	 if statefip==	9	
replace nonmetro=	0		 if statefip==	11	
replace nonmetro=	0.071633958	 if statefip==	12	
replace nonmetro=	0.307799849	 if statefip==	13	
replace nonmetro=	0.245865272	 if statefip==	22	
replace nonmetro=	0.177993457	 if statefip==	26	
replace nonmetro=	0.079224431	 if statefip==	36	
replace nonmetro=	0.391894406	 if statefip==	40	
replace nonmetro=	0.151542647	 if statefip==	48	
replace nonmetro=	0.234945497	 if statefip==	49	

/* 25 states have at least one city that crosses state lines
* Source for proportions of city populations in each state: Census 
  table GCT-PH1: Population, Housing Units Area, and Density: 2000 (SF1)*/

replace bigurban=	0.414412241	 if statefip==	4	
replace bigurban=	0.011355668	 if statefip==	5	
replace bigurban=	0.282950925	 if statefip==	17	
replace bigurban=	0.150714862	 if statefip==	18	
replace bigurban=	0.10598629	 if statefip==	20	
replace bigurban=	0.075349134	 if statefip==	21	
replace bigurban=	0.153141576	 if statefip==	24	
replace bigurban=	0.152262797	 if statefip==	25	
replace bigurban=	0.131562313	 if statefip==	27	
replace bigurban=	0.022491049	 if statefip==	28	
replace bigurban=	0.151907607	 if statefip==	29	
replace bigurban=	0.215681614	 if statefip==	32	
replace bigurban=	0.001811942	 if statefip==	33	
replace bigurban=	0.089741393	 if statefip==	34	
replace bigurban=	0.215302513	 if statefip==	37	
replace bigurban=	0.144795427	 if statefip==	39	
replace bigurban=	0.161220509	 if statefip==	41	
replace bigurban=	0.125408903	 if statefip==	42	
replace bigurban=	0.390805241	 if statefip==	44	
replace bigurban=	0.020518167	 if statefip==	45	
replace bigurban=	0.210530644	 if statefip==	47	
replace bigurban=	0.179054064	 if statefip==	51	
replace bigurban=	0.150236534	 if statefip==	53	
replace bigurban=	0.003924841	 if statefip==	54	
replace bigurban=	0.127589752	 if statefip==	55	

replace bigsubrb=	0.249620572	 if statefip==	4	
replace bigsubrb=	0.00767104	 if statefip==	5	
replace bigsubrb=	0.431470822	 if statefip==	17	
replace bigsubrb=	0.159095622	 if statefip==	18	
replace bigsubrb=	0.156625402	 if statefip==	20	
replace bigsubrb=	0.214556845	 if statefip==	21	
replace bigsubrb=	0.718801822	 if statefip==	24	
replace bigsubrb=	0.419647665	 if statefip==	25	
replace bigsubrb=	0.451598424	 if statefip==	27	
replace bigsubrb=	0.01519327	 if statefip==	28	
replace bigsubrb=	0.397457556	 if statefip==	29	
replace bigsubrb=	0.489057566	 if statefip==	32	
replace bigsubrb=	0.00529123	 if statefip==	33	
replace bigsubrb=	0.736620477	 if statefip==	34	
replace bigsubrb=	0.255833222	 if statefip==	37	
replace bigsubrb=	0.296930475	 if statefip==	39	
replace bigsubrb=	0.298466011	 if statefip==	41	
replace bigsubrb=	0.380113017	 if statefip==	42	
replace bigsubrb=	0.520700703	 if statefip==	44	
replace bigsubrb=	0.020512119	 if statefip==	45	
replace bigsubrb=	0.177718631	 if statefip==	47	
replace bigsubrb=	0.346353879	 if statefip==	51	
replace bigsubrb=	0.318001902	 if statefip==	53	
replace bigsubrb=	0.061380765	 if statefip==	54	
replace bigsubrb=	0.170843691	 if statefip==	55	

replace medmetro=	0.218314625	 if statefip==	4	
replace medmetro=	0.475107728	 if statefip==	5	
replace medmetro=	0.134395332	 if statefip==	17	
replace medmetro=	0.412155445	 if statefip==	18	
replace medmetro=	0.303171977	 if statefip==	20	
replace medmetro=	0.198271846	 if statefip==	21	
replace medmetro=	0.055282691	 if statefip==	24	
replace medmetro=	0.389080526	 if statefip==	25	
replace medmetro=	0.120848773	 if statefip==	27	
replace medmetro=	0.322169836	 if statefip==	28	
replace medmetro=	0.128857875	 if statefip==	29	
replace medmetro=	0.16989106	 if statefip==	32	
replace medmetro=	0.591462438	 if statefip==	33	
replace medmetro=	0.17363813	 if statefip==	34	
replace medmetro=	0.204332593	 if statefip==	37	
replace medmetro=	0.36983601	 if statefip==	39	
replace medmetro=	0.271700261	 if statefip==	41	
replace medmetro=	0.340621171	 if statefip==	42	
replace medmetro=	0.029382278	 if statefip==	44	
replace medmetro=	0.658609197	 if statefip==	45	
replace medmetro=	0.290596196	 if statefip==	47	
replace medmetro=	0.255556427	 if statefip==	51	
replace medmetro=	0.362954883	 if statefip==	53	
replace medmetro=	0.358047473	 if statefip==	54	
replace medmetro=	0.380263159	 if statefip==	55	

replace nonmetro=	0.117652562	 if statefip==	4	
replace nonmetro=	0.505865564	 if statefip==	5	
replace nonmetro=	0.151182922	 if statefip==	17	
replace nonmetro=	0.278034071	 if statefip==	18	
replace nonmetro=	0.434216331	 if statefip==	20	
replace nonmetro=	0.511822175	 if statefip==	21	
replace nonmetro=	0.072773911	 if statefip==	24	
replace nonmetro=	0.039009012	 if statefip==	25	
replace nonmetro=	0.29599049	 if statefip==	27	
replace nonmetro=	0.640145845	 if statefip==	28	
replace nonmetro=	0.321776962	 if statefip==	29	
replace nonmetro=	0.12536976	 if statefip==	32	
replace nonmetro=	0.401434391	 if statefip==	33	
replace nonmetro=	0	 	 if statefip==	34	
replace nonmetro=	0.324531671	 if statefip==	37	
replace nonmetro=	0.188438088	 if statefip==	39	
replace nonmetro=	0.268613219	 if statefip==	41	
replace nonmetro=	0.153856908	 if statefip==	42	
replace nonmetro=	0.059111778	 if statefip==	44	
replace nonmetro=	0.300360517	 if statefip==	45	
replace nonmetro=	0.321154529	 if statefip==	47	
replace nonmetro=	0.219035631	 if statefip==	51	
replace nonmetro=	0.16880668	 if statefip==	53	
replace nonmetro=	0.576646921	 if statefip==	54	
replace nonmetro=	0.321303397	 if statefip==	55	

gen AIPROB=0
label variable AIPROB  "probability of reporting Am. Ind. and/or Alaskan Native"
replace AIPROB=1 if mrmrace==20
gen APIPROB=0
label variable APIPROB "probability of reporting Asian and/or PI"
replace APIPROB=1 if mrmrace==30
gen BPROB=0
label variable BPROB "probability of reporting black"
replace BPROB=1 if mrmrace==40
gen WPROB=0
label variable WPROB "probability of reporting white"
replace WPROB=1 if mrmrace==50

gen constant=1
gen notAI=0   
replace notAI=1 if mrmrace==10
gen notAPI=0
gen notB=0     
replace notB=1 if mrmrace==1 | mrmrace==8

gen northest= 0
replace northest=1 if statefip==09 | statefip==23 |  statefip==25 | statefip==33 | statefip==34 | statefip==36 |  statefip==42 | statefip==44 | statefip==50
 label variable northest "northeast region"

gen midwest= 0
replace midwest=1 if statefip==17 | statefip==18 | statefip==19 | statefip==20 | statefip==26 | statefip==27 |  statefip==29 | statefip==31 | statefip==38 | statefip==39 |  statefip==46 | statefip==55
 label variable midwest "midwest region"

gen south= 0
replace south=1 if statefip==01 | statefip==05 | statefip==10 | statefip==11 | statefip==12 | statefip==13 | statefip==21 | statefip==22 | statefip==24 | statefip==28 | statefip==37 | statefip==40 | statefip==45 | statefip==47 | statefip==48 | statefip==51 | statefip==54
 label variable south "south region"
 
gen west=0
replace west=1 if statefip==02 | statefip==04 | statefip==06 | statefip==08 | statefip==15 | statefip==16 | statefip==30 | statefip==32 | statefip==35 | statefip==41 | statefip==49 | statefip==53 | statefip==56
 label variable west "west region"

* mrmrace=1 IS AI-API    ==> predict AI and API, then rescale
gen mrm1AI =0
label variable mrm1AI "regression answer: AI, MRD group 1"
replace mrm1AI = (notAI    *   0) + (notAPI   *   2.83058) + (notB     *   0.97010) + (age10    *  -0.03967) + (hispanic     *   0.84013) + (male     *   0.01914) + (northest *   0.59649) + (midwest  *   0.43237) +(south    *  -0.22255) + (bigsubrb *   0.15744) + (medmetro *  -0.17318) + (nonmetro *   0.25013) + (lnpctAI  *   0.56512) +(pctAPI   *   0.04203) + (pctB     *   0.03921) + (pct2race *  -0.09723) + (constant *  -5.29417) if mrmrace==1
gen AItemp1= exp(mrm1AI)/(1+exp(mrm1AI)) if mrmrace==1

gen mrm1API =0
label variable mrm1API "regression answer: API, MRD group 1"
replace mrm1API = (notAI    *   2.78725) + (notAPI   *   0) +  (notB     *   1.61570) + (age10    *   0.01946) + (hispanic     *   0.21507) + (male     *   0.01283) + (northest *  -0.13221) + (midwest  *  -0.15172) +(south    *  -0.24854) + (bigsubrb *   0.46028) + (medmetro *  -0.09493) + (nonmetro *  -0.15342) + (lnpctAI  *   0.06996) +(pctAPI   *   0.03741) +  (pctB     *   0.03590) + (pct2race *   0.06402) + (constant *  -5.73987) if mrmrace==1
gen APItemp1= exp(mrm1API)/(1+exp(mrm1API)) if mrmrace==1

gen rescale1=1/(AItemp1+APItemp1)
replace AIPROB = AItemp1 * rescale1 if mrmrace==1
replace APIPROB = APItemp1 * rescale1 if mrmrace==1
drop  mrm1AI AItemp1 mrm1API APItemp1 rescale1

* mrmrace=2 IS AI-B   ==> predict Black
gen mrm2B =0
label variable mrm2B "regression answer: Black, MRD group 2"
replace mrm2B = (age10    *  -0.05461) + (hispanic     *  -1.92602) + (male     *  -0.12359) + (northest *  -0.88349) + (midwest  *  -1.70126) +(south    *  -0.97935) + (bigsubrb *  -0.44211) +  (medmetro *   0.88281) + (nonmetro *  -0.38427) + (lnpctAI  *  -0.43045) +(pctBsq   * 0.0000258) + (pct2race *  -0.16934) + (constant *   3.08086) if mrmrace==2
replace BPROB= exp(mrm2B)/(1+exp(mrm2B)) if mrmrace==2
replace AIPROB= 1-BPROB if mrmrace==2
drop mrm2B

* mrmrace=3 IS AI-W   ==> predict AI 
gen mrm3AI =0
label variable mrm3AI "regression answer: AI, MRD group 3"
replace mrm3AI = (age10    *  -0.08968) + (hispanic     *   0.88834) + (male     *   0.00972) + (northest *   0.21233) + (midwest  *   0.09144) +(south    *  -0.28494) + (bigsubrb *  -0.22069) + (medmetro *  -0.44238) + (nonmetro *  -0.13978) + (lnpctAI  *   0.51235) +(pct2race *  -0.07906) +  (constant *  -0.70527)  if mrmrace==3
replace AIPROB= exp(mrm3AI)/(1+exp(mrm3AI)) if mrmrace==3
replace WPROB= 1-AIPROB if mrmrace==3
drop mrm3AI

* mrmrace=4 IS API-B  ==> predict Black
gen mrm4B =0
label variable mrm4B "regression answer: Black, MRD group 4"
replace mrm4B = (age10    *  0.05669) + (hispanic     * -0.10458) + (male     *  0.33642) +(northest * -0.45997) + (midwest  * -3.92403) +(south    * -1.48264) + (bigsubrb *  1.46590) + (medmetro *  1.67953) + (nonmetro *  0.13301) + (pctAPI   * -0.13245) +(pctB     *  0.02078) + (pct2race *  0.31250) + (constant *  0.45883) if mrmrace==4
replace BPROB= exp(mrm4B)/(1+exp(mrm4B)) if mrmrace==4
replace APIPROB= 1-BPROB if mrmrace==4
drop mrm4B

* mrmrace=5 IS API-W  ==> predict API 
gen mrm5API =0
label variable mrm5API "regression answer: API, MRD group 5"
replace mrm5API = (age10    *  0.09568) + (hispanic     *  0.19303) + (male     *  0.01393) + (northest * -0.05520) +  (midwest  * -0.06453) + (south    *  0.12694) +  (bigsubrb *  0.50556) +  (medmetro *  0.07443) +  (nonmetro * -0.62956) +  (pctAPI   *  0.00735) + (pct2race *  0.09791) +  (constant * -1.18887) if mrmrace==5
replace APIPROB= exp(mrm5API)/(1+exp(mrm5API)) if mrmrace==5
replace WPROB= 1-APIPROB if mrmrace==5
drop mrm5API

* mrmrace=6 IS B-W    ==> predict Black
gen mrm6B =0
label variable mrm6B "regression answer: Black, MRD group 6"
replace mrm6B = (age10    *  0.05532) + (hispanic     * -0.52253) +  (male     *  0.11948) +  (northest * -0.25363) +  (midwest  *  0.17140) + (south    * -0.64386) +  (bigsubrb * -0.07649) +  (medmetro *  0.28938) +  (nonmetro *  0.57636) +  (pctBsq   *  0.00079) +  (pct2race *  0.31679) +  (constant * -0.17533) if mrmrace==6
replace BPROB= exp(mrm6B)/(1+exp(mrm6B)) if mrmrace==6
replace WPROB= 1-BPROB if mrmrace==6
drop mrm6B

* mrmrace=7 IS AI-API-B  ==> predict AI, API, and B, then rescale
gen mrm7AI =0
label variable mrm7AI "regression answer: AI, MRD group 7"
replace mrm7AI = (notAI    *   0) + (notAPI   *   2.83058) +  (notB     *   0.97010) +  (age10    *  -0.03967) +  (hispanic     *   0.84013) +  (male     *   0.01914) +  (northest *   0.59649) +  (midwest  *   0.43237) + (south    *  -0.22255) +  (bigsubrb *   0.15744) +  (medmetro *  -0.17318) +  (nonmetro *   0.25013) +  (lnpctAI  *   0.56512) + (pctAPI   *   0.04203) +  (pctB     *   0.03921) +  (pct2race *  -0.09723) +  (constant *  -5.29417) if mrmrace==7

gen mrm7API =0
label variable mrm7API "regression answer: API, MRD group 7"
replace mrm7API = (notAI    *   2.78725) + (notAPI   *   0) +  (notB     *   1.61570) +  (age10    *   0.01946) +  (hispanic     *   0.21507) +  (male     *   0.01283) +  (northest *  -0.13221) +  (midwest  *  -0.15172) + (south    *  -0.24854) +  (bigsubrb *   0.46028) +  (medmetro *  -0.09493) +  (nonmetro *  -0.15342) +  (lnpctAI  *   0.06996) + (pctAPI   *   0.03741) +  (pctB     *   0.03590) +  (pct2race *   0.06402) +  (constant *  -5.73987) if mrmrace==7

gen mrm7B =0
label variable mrm7B "regression answer: B, MRD group 7"
replace mrm7B = (notAI    *   2.19772) + (notAPI   *   3.06153) +  (notB     *   0) +  (age10    *  -0.01691) +  (hispanic     *  -0.58721) +  (male     *  -0.08093) +  (northest *   0.40115) +  (midwest  *   0.20136) + (south    *  -0.29365) +  (bigsubrb *   0.12070) +  (medmetro *  -0.11129) +  (nonmetro *  -0.12077) +  (lnpctAI  *  -0.00347) + (pctAPI   *   0.05396) +  (pctB     *   0.05893) +  (pct2race *  -0.03953) +  (constant *  -5.21431) if mrmrace==7

gen AItemp7= exp(mrm7AI)/(1+exp(mrm7AI)+exp(mrm7API)+exp(mrm7B)) if mrmrace==7
gen APItemp7= exp(mrm7API)/(1+exp(mrm7API)+exp(mrm7API)+exp(mrm7B)) if mrmrace==7
gen Btemp7= exp(mrm7B)/(1+exp(mrm7API)+exp(mrm7API)+exp(mrm7B)) if mrmrace==7
gen resc7=AItemp7+APItemp7+Btemp7 if mrmrace==7
gen rescale7=1/resc7 
replace AIPROB  = AItemp7  * rescale7 if mrmrace==7
replace APIPROB = APItemp7 * rescale7 if mrmrace==7
replace BPROB = Btemp7   * rescale7 if mrmrace==7
drop  mrm7AI mrm7API mrm7B APItemp7 AItemp7 Btemp7 resc7 rescale7

* mrmrace=8 IS AI-API-W  ==> predict AI and API, white is remainder
gen mrm8AI =0
label variable mrm8AI "regression answer: AI, MRD group 8"
replace mrm8AI = (notAI    *   0) + (notAPI   *   2.83058) +  (notB     *   0.97010) +  (age10    *  -0.03967) +  (hispanic     *   0.84013) +  (male     *   0.01914) +  (northest *   0.59649) +  (midwest  *   0.43237) + (south    *  -0.22255) +  (bigsubrb *   0.15744) +  (medmetro *  -0.17318) +  (nonmetro *   0.25013) +  (lnpctAI  *   0.56512) + (pctAPI   *   0.04203) +  (pctB     *   0.03921) +  (pct2race *  -0.09723) +  (constant *  -5.29417)  if mrmrace==8

gen mrm8API =0
label variable mrm8API "regression answer: API, MRD group 8"
replace mrm8API = (notAI    *   2.78725) + (notAPI   *   0) +  (notB     *   1.61570) +  (age10    *   0.01946) +  (hispanic     *   0.21507) +  (male     *   0.01283) +  (northest *  -0.13221) +  (midwest  *  -0.15172) + (south    *  -0.24854) +  (bigsubrb *   0.46028) +  (medmetro *  -0.09493) +  (nonmetro *  -0.15342) +  (lnpctAI  *   0.06996) + (pctAPI   *   0.03741) +  (pctB     *   0.03590) +  (pct2race *   0.06402) +  (constant *  -5.73987)  if mrmrace==8

replace AIPROB = exp(mrm8AI) /(1+exp(mrm8AI)+exp(mrm8API)) if mrmrace==8
replace APIPROB= exp(mrm8API)/(1+exp(mrm8AI)+exp(mrm8API)) if mrmrace==8
replace WPROB= 1-AIPROB-APIPROB if mrmrace==8
drop mrm8AI mrm8API

* mrmrace=9 IS AI-B-W ==> predict AI and B, white is remainder

gen mrm9AI =0
label variable mrm9AI "regression answer: AI, MRD group 9"
replace mrm9AI = (age10    *  0.26212) +  (hispanic     *  0.35986) + (male     * -0.43898) +  (northest * -4.53976) +  (midwest  * -3.82328) + (south    * -5.73385) +  (bigsubrb *  2.78910) +  (medmetro *  2.27176) +  (nonmetro *  4.17804) +  (pctAI    *  0.54579) + (pctB     *  0.11100) +  (pct2race * -0.23972) +  (constant * -0.64594) if mrmrace==9

gen mrm9B =0
label variable mrm9B "regression answer: B, MRD group 9"
replace mrm9B = (age10    *  0.36140) +  (hispanic     * -0.83526) +  (male     *  0.50777) +  (northest * -3.45593) +  (midwest  * -3.79144) + (south    * -2.27313) +  (bigsubrb *  2.31011) +  (medmetro *  0.75477) +  (nonmetro *  1.64725) +  (pctAI    *  0.39101) + (pctB     *  0.04985) +  (pct2race * -0.02919) +  (constant *  0.77004) if mrmrace==9

replace AIPROB= exp(mrm9AI)/(1+exp(mrm9AI)+exp(mrm9B)) if mrmrace==9
replace BPROB= exp(mrm9B)/(1+exp(mrm9AI)+exp(mrm9B)) if mrmrace==9
replace WPROB=1-BPROB-AIPROB if mrmrace==9
drop mrm9AI mrm9B

* MARS=10 IS API-B-W  ==> predict API and B, white is remainder
gen mrm10AP =0
label variable mrm10AP "regression answer: API, MRD group 10"
replace mrm10AP = (notAI    *   2.78725) + (notAPI   *   0) +  (notB     *   1.61570) +  (age10    *   0.01946) +  (hispanic     *   0.21507) +  (male     *   0.01283) +  (northest *  -0.13221) +  (midwest  *  -0.15172) + (south    *  -0.24854) +  (bigsubrb *   0.46028) +  (medmetro *  -0.09493) +  (nonmetro *  -0.15342) +  (lnpctAI  *   0.06996) + (pctAPI   *   0.03741) +  (pctB     *   0.03590) +  (pct2race *   0.06402) +  (constant *  -5.73987) if mrmrace==10

gen mrm10B =0
label variable mrm10B "regression answer: B, MRD group 10"
replace mrm10B = (notAI    *   2.19772) + (notAPI   *   3.06153) +  (notB     *   0) +  (age10    *  -0.01691) +  (hispanic     *  -0.58721) +  (male     *  -0.08093) +  (northest *   0.40115) +  (midwest  *   0.20136) + (south    *  -0.29365) +  (bigsubrb *   0.12070) +  (medmetro *  -0.11129) +  (nonmetro *  -0.12077) +  (lnpctAI  *  -0.00347) + (pctAPI   *   0.05396) +  (pctB     *   0.05893) +  (pct2race *  -0.03953) +  (constant *  -5.21431) if mrmrace==10

replace APIPROB= exp(mrm10AP)/(1+exp(mrm10AP)+exp(mrm10B)) if mrmrace==10
replace BPROB= exp(mrm10B)/(1+exp(mrm10AP)+exp(mrm10B)) if mrmrace==10
replace WPROB=1-BPROB-APIPROB if mrmrace==10
drop mrm10AP mrm10B

* MARS=11 IS AI-API-B-W ==> predict AI, API, and B, white is remainder
gen mrm11AI =0
label variable mrm11AI "regression answer: AI, MRD group 11"
replace mrm11AI = (notAI    *   0) + (notAPI   *   2.83058) +  (notB     *   0.97010) +  (age10    *  -0.03967) +  (hispanic     *   0.84013) +  (male     *   0.01914) +  (northest *   0.59649) +  (midwest  *   0.43237) + (south    *  -0.22255) +  (bigsubrb *   0.15744) +  (medmetro *  -0.17318) +  (nonmetro *   0.25013) +  (lnpctAI  *   0.56512) + (pctAPI   *   0.04203) +  (pctB     *   0.03921) +  (pct2race *  -0.09723) +  (constant *  -5.29417) if mrmrace==11

gen mrm11AP =0
label variable mrm11AP "regression answer: API, MRD group 11"
replace mrm11AP = (notAI    *   2.78725) + (notAPI   *   0) +  (notB     *   1.61570) +  (age10    *   0.01946) +  (hispanic     *   0.21507) +  (male     *   0.01283) +  (northest *  -0.13221) +  (midwest  *  -0.15172) + (south    *  -0.24854) +  (bigsubrb *   0.46028) +  (medmetro *  -0.09493) +  (nonmetro *  -0.15342) +  (lnpctAI  *   0.06996) + (pctAPI   *   0.03741) +  (pctB     *   0.03590) +  (pct2race *   0.06402) +  (constant *  -5.73987) if mrmrace==11

gen mrm11B =0
label variable mrm11B "regression answer: B, MRD group 11"
replace mrm11B = (notAI    *   2.19772) + (notAPI   *   3.06153) +  (notB     *   0) +  (age10    *  -0.01691) +  (hispanic     *  -0.58721) +  (male     *  -0.08093) +  (northest *   0.40115) +  (midwest  *   0.20136) + (south    *  -0.29365) +  (bigsubrb *   0.12070) +  (medmetro *  -0.11129) +  (nonmetro *  -0.12077) +  (lnpctAI  *  -0.00347) + (pctAPI   *   0.05396) +  (pctB     *   0.05893) +  (pct2race *  -0.03953) +  (constant *  -5.21431) if mrmrace==11

replace AIPROB= exp(mrm11AI)/(1+exp(mrm11AI)+exp(mrm11AP)+exp(mrm11B)) if mrmrace==11
replace APIPROB= exp(mrm11AP)/(1+exp(mrm11AI)+exp(mrm11AP)+exp(mrm11B)) if mrmrace==11
replace BPROB= exp(mrm11B)/(1+exp(mrm11AI)+exp(mrm11AP)+exp(mrm11B)) if mrmrace==11
replace WPROB=1-AIPROB-APIPROB-BPROB if mrmrace==11
drop mrm11AI mrm11AP mrm11B

drop  lnpctAI pctAI pctAPI pctB pctBsq pct2race medmetro nonmetro bigurban bigsubrb constant notAI notAPI notB northest midwest south west

/* Note: When converting probabilities to ONERACE, equal probabilities 
are decided in favor of the single-race group that has a higher average 
probability listed in Table 9 of Ingram et al. 2003.*/

gen ONERACE=0
replace ONERACE=1 if mrmrace==20
replace ONERACE=2 if mrmrace==30
replace ONERACE=3 if mrmrace==40
replace ONERACE=4 if mrmrace==50
replace ONERACE=5 if mrmrace==60

replace ONERACE=1 if mrmrace==1 & AIPROB>0.5
replace ONERACE=2 if mrmrace==1 & APIPROB>=0.5

replace ONERACE=1 if mrmrace==2 & AIPROB>0.5
replace ONERACE=3 if mrmrace==2 & BPROB>=0.5

replace ONERACE=1 if mrmrace==3 & AIPROB>0.5
replace ONERACE=4 if mrmrace==3 & WPROB>=0.5

replace ONERACE=2 if mrmrace==4 & APIPROB>0.5
replace ONERACE=3 if mrmrace==4 & BPROB>=0.5

replace ONERACE=2 if mrmrace==5 & APIPROB>0.5
replace ONERACE=4 if mrmrace==5 & WPROB>=0.5

replace ONERACE=4 if mrmrace==6 & WPROB>0.5
replace ONERACE=3 if mrmrace==6 & BPROB>=0.5

replace ONERACE=2 if mrmrace==7 & APIPROB>BPROB   & APIPROB>AIPROB
replace ONERACE=1 if mrmrace==7 & AIPROB>=APIPROB & AIPROB>BPROB
replace ONERACE=3 if mrmrace==7 & BPROB>=APIPROB  & BPROB>=AIPROB

replace ONERACE=1 if mrmrace==8 & AIPROB>APIPROB  & AIPROB>WPROB
replace ONERACE=2 if mrmrace==8 & APIPROB>=AIPROB & APIPROB>WPROB
replace ONERACE=4 if mrmrace==8 & WPROB>=AIPROB   & WPROB>=APIPROB

replace ONERACE=1 if mrmrace==9 & AIPROB>BPROB    & AIPROB>WPROB
replace ONERACE=4 if mrmrace==9 & WPROB>=AIPROB   & WPROB>BPROB
replace ONERACE=3 if mrmrace==9 & BPROB>=AIPROB   & BPROB>=WPROB

replace ONERACE=2 if mrmrace==10 & APIPROB>BPROB  & APIPROB>WPROB
replace ONERACE=3 if mrmrace==10 & BPROB>=APIPROB & BPROB>WPROB
replace ONERACE=4 if mrmrace==10 & WPROB>=APIPROB & WPROB>=BPROB

replace ONERACE=2 if mrmrace==11 & APIPROB>AIPROB & APIPROB>BPROB & APIPROB>WPROB
replace ONERACE=1 if mrmrace==11 & AIPROB>=APIPROB & AIPROB>BPROB & AIPROB>WPROB
replace ONERACE=3 if mrmrace==11 & BPROB>=APIPROB & BPROB>=AIPROB & BPROB>WPROB
replace ONERACE=4 if mrmrace==11 & WPROB>=APIPROB & WPROB>=AIPROB & WPROB>=BPROB

label variable ONERACE "bridged single race"
label define onerace 1 "1 - Am.Ind." 2 "2 - Asian/PI" 3 "3 - Black" 4 "4 - White" 5 "5 - SOR"
label values ONERACE onerace

compress 

rename ONERACE onerace
tab onerace, missing

* check to makes sure all codes in RACE map onto the bridge race category
	* if there are any observations receiving ONERACE = 1 then these codes must be added to the race dummies categories
tab race year if onerace == 0

save "`racebridge'", replace



